﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;

namespace ShevaEngine.Core.Foundation
{
    /// <summary>Quad.</summary>
    public class Quad2D
    {
        /// <summary>Center.</summary>
        public Vector3 Center;
        /// <summary>Dimension.</summary>
        public Vector2 Dimension;

        /// <summary>
        /// Constructor.
        /// </summary>
        public Quad2D()
        {
            this.Center = Vector3.Zero;
            this.Dimension = Vector2.Zero;
        }

         /// <summary>
        /// Funkce zjisti, zda-li bod lezi uvnitr trojuhelniku.
        /// </summary>
        /// <param name="vertex"></param>        
        /// <returns></returns>
        public bool ContainsVertex(Vector3 vertex)
        {
            return
                (Math.Abs(vertex.X - this.Center.X) <= (this.Dimension.X / 2)) &&
                (Math.Abs(vertex.Z - this.Center.Z) <= (this.Dimension.Y / 2));
        }

        /// <summary>
        /// Method returns border vertices.
        /// </summary>
        /// <returns></returns>
        public List<Vector3> GetBorderVertices()
        {
            List<Vector3> output = new List<Vector3>(4);            

            output.Add(this.Center + new Vector3(-this.Dimension.X / 2, 0, -this.Dimension.Y / 2));
            output.Add(this.Center + new Vector3(-this.Dimension.X / 2, 0, this.Dimension.Y / 2));
            output.Add(this.Center + new Vector3(this.Dimension.X / 2, 0, this.Dimension.Y / 2));
            output.Add(this.Center + new Vector3(this.Dimension.X / 2, 0, -this.Dimension.Y / 2));

            return output;
        }
    }
}
